import type TableColumn from "@/components/table/type/TableColumn.ts";
import type FormItem from "@/components/form/type/FormItem.ts";
import {reactive} from "vue";

const useSchema = () => {

    //修改密码模型数据
    const passwordChangeModel = reactive({
        oldPassword: '',
        newPassword: '',
        confirmPassword: ''
    })

    const checkPassword = (val: string): true | string => {
        if (val.length > 0 && val === passwordChangeModel.oldPassword) {
            return '新老密码不能一致'
        }
        return true
    }

    const checkConfirmPassword = (val: string): true | string => {
        if (val === passwordChangeModel.newPassword) {
            return true
        }
        return '密码输入不一致'
    }

    /**
     * 修改密码的表单结构数据
     */
    const passwordSchema: FormItem[] = [
        {row: 0, span: 24, label: "旧密码", key: "oldPassword", type: "password"},
        {row: 1, span: 24, label: "新密码", key: "newPassword", type: "password", rules: [checkPassword]},
        {row: 2, span: 24, label: "确认密码", key: "confirmPassword", type: "password", rules: [checkConfirmPassword]},
    ]


    /**
     * 表格结构数据
     */
    const tableColumns: TableColumn[] = [
        {key: "currentDepart", title: "选择", width: 80, align: "center", type: "radio"},
        {key: "departName", title: "部门名称", align: "center", type: "string"},
        {key: "departCode", title: "部门编码", align: "center", type: "string"},
    ]

    return {passwordChangeModel, passwordSchema, tableColumns}
}

export default useSchema